package my.mark.mybaibaoxiang.eventDemo.spring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;

/**
 * @author twotiger-wxm.
 * @date 2019-8-26.
 */
@Configuration
public class StartListener {
    final static Logger logger = LoggerFactory.getLogger(StartListener.class);

    /**
     * 当所有的bean都已经处理完成之后，spring ioc容器会有一个发布事件的动作。
     * ContextRefreshedEvent,监听项目启动后的事件，项目启动要做的事可在这做。
     * ：@EventListener注解会去监听传过来的参数事件。
     * @param event
     */
    @EventListener
    public void FirstEventListener(ContextRefreshedEvent event) {
        logger.info("===================ContextRefreshedEvent走了");
        /*List<WarnRule> lists = null;
        try {
            lists = warnRuleService.getList();
        }catch (Exception e){
            e.printStackTrace();
        }
        if(lists != null && lists.size() >0) {
            for (WarnRule warnRule : lists) {
                warnRuleService.startSchedule(warnRule);
            }
        }*/
    }
}
